<template>
	<view class="bg">
		<view class="content">
			<!-- <u-navbar :is-back="true" :title="title"></u-navbar> -->
			<!-- 顶部 -->
			<view class="header">
				<view class="head_image">
					<image :src="avatar" @tap="binduser(1)" style="border-radius: 50%;"></image>
				</view>
				<view class="head_name" v-if="userId">
					<view class="name" @tap="binduser(2)">{{nickName}}</view>
					<view class="approve" v-if="checkCertification=='0'&&shangxian=='否'">实名认证审核中</view>
					<view class="approve" v-if="checkCertification=='1'&&shangxian=='否'">已实名</view>
					<view class="flex align-center approve" v-if="checkCertification=='2'&&shangxian=='否'">
						<view class="" @click="bindapprove">实名认证未通过</view>
						<view class="margin-left" style="color: red;">{{checkCertificationMessage}}</view>
					</view>
					<view class="approve" @click="bindapprove"
						v-if="(checkCertification==null||checkCertification=='')&&shangxian=='否'">未实名认证</view>
				</view>
				<view class="head_name" v-if="!userId">
					<button class="logins" @click="goLogin">登录</button>
				</view>
			</view>
		</view>
		<!-- 收入和订单 -->
		<view style="border-radius: 24rpx;overflow: hidden;width: 93%;margin: 0 auto;background: #ffffff;"
			v-if="shangxian=='否'">
			<view class="user_box">
				<view class="box">
					<view class="user_name" @click="bindmy('/pages/riderMy/myAccount/myAccount')">
						<u-section title="今日收入" :right="false" line-color="#FE3B27"></u-section>
					</view>
					<view class="user_price">{{indent.incomeday?indent.incomeday:0}} <text>元</text></view>
					<view class="user_tit ">今日收入金额</view>
				</view>
				<view class="box" @click="bindmy('/pages/riderMy/myAccount/myAccount')">
					<view class="user_name">
						<u-section title="本月收入" :right="false" line-color="#009C66"></u-section>
					</view>
					<view class="user_price">{{indent.incomemonth?indent.incomemonth:0}} <text>元</text></view>
					<view class="user_tit ">本月收入金额</view>
				</view>
			</view>
			<view class="user_box">
				<view class="box" @click="bindmy('/pages/riderMy/myAccount/myAccount')">
					<view class="user_name">
						<u-section title="累计收入" :right="false" line-color="#FE3B27"></u-section>
					</view>
					<view class="user_price">{{indent.incomesum?indent.incomesum:0}} <text>元</text></view>
					<view class="user_tit ">累计收入金额</view>
				</view>
				<view class="box" @click="myOrders()">
					<view class="user_name">
						<u-section title="订单统计" :right="false" line-color="#009C66"></u-section>
					</view>
					<view class="user_price">{{indent.indentCount?indent.indentCount:0}} <text>单</text></view>
					<view class="user_tit ">今日完成单量</view>
				</view>
			</view>
		</view>
		<!-- 我的列表 -->
		<view class="mylist ">
			<!-- #ifdef MP-WEIXIN -->
			<view class="list_box" v-if="shangxian=='否'" @click="bindMsg">
				<view class="list_left">
					<image src="../../static/my/icon_11.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">订阅消息</view>
				</view>
				<view class="jia">
					<view>+</view>
				</view>
			</view>
			<!-- #endif -->
			<view class="list_box" @click="bindmy('/pages/riderMy/trainingList')">
				<view class="list_left">
					<image src="../../static/my/icon_11.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">骑手指南</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view>
			<view class="list_box" @click="bindmy('/pageA/expressOrder/index')">
				<view class="list_left">
					<image src="../../static/my/paihangb.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">快递订单</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view>
			<!-- <view class="list_box" @click="bindmy('/pages/riderMy/payment/index')">
				<view class="list_left">
					<image src="../../static/my/icon_11.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">提现到微信</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view> -->
			
			<view class="list_box" @click="bindmy('/pages/riderMy/myAccount/myAccount')" v-if="shangxian=='否'">
				<view class="list_left">
					<image src="../../static/my/icon_22.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">资金账户</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view>
			<view class="list_box" @click="bindmy('/pages/riderMy/myComment/myComment')" v-if="shangxian=='否'">
				<view class="list_left">
					<image src="../../static/my/icon_33.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">我的评价</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view>
			<view class="list_box" @click="bindmy('/pages/riderMy/myComplain/myComplain')">
				<view class="list_left">
					<image src="../../static/my/icon_44.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">违规申诉</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view>
			<view class="list_box" @click="bindmy('/pages/riderMy/paihangbang')">
				<view class="list_left">
					<image src="../../static/my/paihangb.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">骑手排行榜</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view>
		
			
			<!-- <view class="list_box" @click="bindmy('/pageA/driverRoute/index')">
				<view class="list_left">
					<image src="../../static/my/paihangb.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">司机路线</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view> -->
			
			<view class="list_box" @click="bindmy('/pages/riderMy/kefu/kefu')">
				<view class="list_left">
					<image src="../../static/my/icon_66.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">联系客服</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view>
			<view class="list_box" @click="bindmy('/pages/riderMy/feedback/feedback')">
				<view class="list_left">
					<image src="../../static/my/icon_55.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">意见反馈</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view>
			<view class="list_box" @click="bindmy('/pages/riderMy/xieyi')">
				<view class="list_left">
					<image src="../../static/my/icon_33.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">用户协议</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view>
			<view class="list_box" @click="bindmy('/pages/riderMy/mimi')">
				<view class="list_left">
					<image src="../../static/my/icon_99.png" mode="scaleToFill" class=""
						style="width:33upx;height:33upx"></image>
					<view class="list_name margin-left-sm">隐私政策</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view>
			<view class="list_box" @click="TuiLogin">
				<view class="list_left">
					<image src="../../static/rider/55.png" mode="scaleToFill" class="list_img"></image>
					<view class="list_name">退出登录</view>
				</view>
				<image src="../../static/my/icon_go.png" class="list_right"></image>
			</view>
		</view>
	</view>
</template>

<script>
	import configdata from '../../common/config.js';
	export default {
		onShareAppMessage(res) { //发送给朋友
			return {
				title: this.tuiguang,
				path: '/pages/index/index',
				imageUrl: this.tuiguangImg,
			}
		},
		onShareTimeline(res) { //分享到朋友圈
			return {
				title: this.tuiguang,
				path: '/pages/index/index',
				imageUrl: this.tuiguangImg,
			}
		},
		data() {

			return {
				tuiguang: '',
				tuiguangImg: '',
				show: false,
				title: '我的',
				information: {}, //个人信息
				daySr: '',
				orders: '',
				indent: {},
				arrs: [],
				avatar: '../../static/logo.png',
				nickName: '匿名',
				checkCertification: '',
				userId: '',
				token: '',
				shangxian: '是',
				checkCertificationMessage: ''
			}
		},
		onLoad() {
			this.shangxian = uni.getStorageSync('shangxian')
			this.$Request.getT('/app/common/type/276').then(res => {
				if (res.code === 0) {
					uni.setStorageSync('tuiguang', res.data.value)
					this.tuiguang = res.data.value;
				}
			});
			this.$Request.getT('/app/common/type/277').then(res => {
				if (res.code === 0) {
					uni.setStorageSync('tuiguangImg', res.data.value)
					this.tuiguangImg = res.data.value;
				}
			});

			this.$Request.getT('/app/common/type/338').then(res => { //骑手新订单通知
				if (res.code == 0) {
					if (res.data && res.data.value) {
						this.arrs.push(res.data.value)
					}
				}
			})
			this.$Request.getT('/app/common/type/293').then(res => { //订单完成通知
				if (res.code == 0) {
					if (res.data && res.data.value) {
						this.arrs.push(res.data.value)
					}
				}
			})
			this.$Request.getT('/app/common/type/292').then(res => { //接单成功
				if (res.code == 0) {
					if (res.data && res.data.value) {
						this.arrs.push(res.data.value)
					}
				}
			})

		},
		onShow() {

			this.token = this.$queue.getData('token');
			this.userId = this.$queue.getData('userId');
			if (this.token) {
				this.shouru()
				this.getUserInfo(this.userId);
			} else {
				// this.goLogin();
			}


		},
		methods: {
			bindMsg() {
				// #ifdef MP-WEIXIN
				uni.requestSubscribeMessage({
					tmplIds: this.arrs,
					success(re) {
						// console.log(re,'**********')
						var datas = JSON.stringify(re);
						if (datas.indexOf("accept") != -1) {
							console.log(re)
						}
					},
					fail: (res) => {
						console.log(res)
					}
				})
				// #endif
			},
			// 查看今日收入
			profit() {
				if (!this.userId) {
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return
				}
				uni.navigateTo({
					url: '/pages/riderMy/profit'
				})
			},
			// 查看订单统计
			myOrders() {
				if (!this.userId) {
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return
				}
				uni.navigateTo({
					url: '/pages/riderMy/order'
				})
			},
			bindapprove() {
				uni.navigateTo({
					url: '/pages/riderMy/approve/approve'
				})
			},
			bindmy(e) {
				let that = this
				console.log(e);
				if (that.token) {
					// #ifdef MP-WEIXIN
					if (uni.getStorageSync('sendMsg')) {
						uni.requestSubscribeMessage({
							tmplIds: this.arrs,
							success(re) {
								// console.log(re,'**********')
								var datas = JSON.stringify(re);
								if (datas.indexOf("accept") != -1) {
									console.log(re)
									// uni.showToast({
									// 	title: '订阅成功',
									// 	icon: 'none'
									// })
								}
							},
							fail: (res) => {
								console.log(res)
							}
						})
					}
					// #endif
					uni.navigateTo({
						url: e
					})
				} else {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}
			},
			binduser(index) {
				let token = this.$queue.getData('token');
				if (!token) {
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return;
				}
				if (index == 2) {
					uni.navigateTo({
						url: '/pages/riderMy/userphone/userphone'
					});
				}

				if (index == 1) {
					let that = this;
					var url = null;
					let userId = this.$queue.getData('userId');
					uni.showActionSheet({
						// itemList按钮的文字接受的是数组
						itemList: ["查看头像", "从相册选择图片"],
						success(e) {
							var index = e.tapIndex
							if (index === 0) {
								// 用户点击了预览当前图片
								// 可以自己实现当前头像链接的读取
								let url = that.image_url;
								let arr = []
								arr.push(url)
								uni.previewImage({
									// 预览功能图片也必须是数组的
									urls: arr
								})
							} else if (index === 1) {
								uni.chooseImage({
									count: 1, //默认9
									sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
									sourceType: ['album'], //从相册选择
									success: function(res) {
										uni.showLoading({
											title: '上传中...'
										});
										let token = uni.getStorageSync('token');
										uni.uploadFile({
											url: that.config("APIHOST1") +
												'/alioss/upload', //仅为示例，非真实的接口地址
											filePath: res.tempFilePaths[0],
											header: {
												token: token
											},
											name: 'file',
											success: uploadFileRes => {
												url = JSON.parse(uploadFileRes.data).data;
												let datafrom = {
													avatar: url
												}

												// console.log(JSON.parse(uploadFileRes.data).data)
												that.$Request.postJson(
														'/app/user/updateUser', datafrom)
													.then(
														res => {
															uni.hideLoading();
															if (res.code === 0) {
																that.$queue.showToast(
																	"更新成功");
																that.getUserInfo(that
																	.userId);
															}
														});
											}
										});
									}
								});
							}
						}
					})
				}
			},
			config: function(name) {
				var info = null;
				if (name) {
					var name2 = name.split("."); //字符分割
					if (name2.length > 1) {
						info = configdata[name2[0]][name2[1]] || null;
					} else {
						info = configdata[name] || null;
					}
					if (info == null) {
						let web_config = cache.get("web_config");
						if (web_config) {
							if (name2.length > 1) {
								info = web_config[name2[0]][name2[1]] || null;
							} else {
								info = web_config[name] || null;
							}
						}
					}
				}
				return info;
			},
			// 获取个人信息
			getUserInfo(userId) {
				this.$Request.getT("/app/userinfo/findUserInfoById").then(res => {
					if (res.code == 0) {
						this.$nextTick(function() {
							this.avatar = res.data.avatar ? res.data.avatar : '../../static/logo.png'
							uni.getStorageSync('avatar', res.data.avatar)
							this.nickName = res.data.nickName
							this.checkCertification = res.data.checkCertification
							this.checkCertificationMessage = res.data.checkCertificationMessage
							console.log(this.checkCertification, '实名认证')
							this.userId = res.data.userId
						})
					} else {
						this.$queue.logout();
						uni.showModal({
							showCancel: false,
							title: '登录失败',
							content: res.msg,
						});
					}
				});
			},
			// 今日收入、订单量
			shouru() {
				this.$Request.getT('/app/userinfo/findIncome').then(res => {
					if (res.code == 0) {
						// this.daySr = res.data.income
						// this.orders = res.data.indentCount
						this.indent = res.data
					}
					console.log('res', res)

				});
			},
			// 跳转去登录
			goLogin() {
				// this.$queue.setData('href', '/pages/my/index');
				uni.navigateTo({
					url: '/pages/login/login'
				});
			},
			//退出登录
			TuiLogin() {
				let that = this

				if (that.userId) {
					uni.showModal({
						title: '提示',
						content: '确认退出登录吗?',
						success: function(res) {
							if (res.confirm) {
								uni.removeStorageSync('userId')
								uni.removeStorageSync('token')
								uni.removeStorageSync('avatar')
								uni.removeStorageSync('nickName')
								uni.removeStorageSync('phone')
								uni.removeStorageSync('invitationCode')
								uni.removeStorageSync('inviterCode')
								uni.removeStorageSync('platform')
								uni.removeStorageSync('sex')
								uni.removeStorageSync('zhiFuBao')
								uni.removeStorageSync('zhiFuBaoName')
								uni.removeStorageSync('checkCertification')

								// uni.navigateBack()
								uni.redirectTo({
									url: '/pages/index/index'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				} else {
					uni.showModal({
						title: '提示',
						content: '您还未登录,请先登录',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/pages/login/login'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				}


			},
		}
	}
</script>

<style>
	.u-icon__icon {
		font-size: 35rpx !important;
		font-weight: bold !important;
	}

	.u-title {
		color: #000000 !important;
	}

	.u-navbar-fixed {
		background: none !important;
	}

	body {
		background: #F5F5F5;
	}

	.bg {}

	.logins {
		border: none;
		background: #F8501F;
		color: #fff;
		width: 200rpx;
		margin: 70rpx 20rpx;
		height: 70rpx;
		line-height: 70rpx;
	}

	.content {
		background: linear-gradient(0deg, #F5F5F5 0%, #fed9ba 100%);
		width: 100%;
	}

	/* 顶部 */
	.header {
		width: 100%;
		height: 200rpx;
		display: flex;
	}

	.head_image {
		flex: 1;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.head_image image {
		width: 90rpx;
		height: 90rpx;
	}

	.head_name {
		flex: 4;
		position: relative;
		margin-left: -14rpx;
	}

	.name {
		position: absolute;
		top: 65rpx;
	}

	.jia {
		background: #346EF6;
		border-radius: 50%;
		width: 44rpx;
		height: 44rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #FFFFFF;
	}

	.approve {
		position: absolute;
		top: 100rpx;
		font-size: 24rpx;
		color: #999999;
	}

	/* 用户信息 */
	.user_box {
		display: flex;
		height: 210rpx;

		position: relative;
		top: -15rpx;
		padding: 0 20rpx;
	}

	.box {
		flex: 1;
		/* margin-left: 40rpx; */
		margin-top: 40rpx;
	}

	.user_price {
		font-size: 44rpx;
		margin-top: 10rpx;
	}

	.user_price text {
		font-size: 21rpx;
		margin-left: 10rpx;
	}

	.user_tit {
		color: #B3B3B3;
		font-size: 21rpx;
		margin-top: 10rpx;
	}

	.u-section__title {
		font-weight: 500 !important;
		color: #333333 !important;
		font-size: 14px !important;
		padding-left: 10px;
	}

	/* 我的列表 */
	.mylist {
		width: 93%;
		margin: 0 auto;
		background-color: #FFFFFF;
		margin-top: 10rpx;
		border-radius: 23rpx;
		padding: 0upx 30upx;
	}

	.list_box {
		/* width: 90%; */
		/* margin: 0 auto; */
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 95rpx;
	}

	.list_left {
		flex: 1;
		display: flex;
		justify-content: left;
		align-items: center;
	}

	.list_img {
		width: 44rpx;
		height: 44rpx;
		margin-right: 10rpx;
	}

	.list_name {
		font-size: 25rpx;
		letter-spacing: 2rpx;
	}


	.list_right {
		width: 12rpx;
		height: 20rpx;
	}
</style>